/*
package com.heima.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.constants.user.UserConstans;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.dtos.AuthDto;
import com.heima.model.user.pojos.ApUser;
import com.heima.model.user.pojos.ApUserRealname;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.user.feign.ArticleFeign;
import com.heima.user.feign.WemediaFeign;
import com.heima.user.mapper.ApUserMapper;
import com.heima.user.mapper.ApUserRealnameMapper;
import com.heima.user.service.ApUserRealnameService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

*/
/**
 * 认证用户业务
 *//*

@Service
public class ApUserRealnameServiceImpl extends ServiceImpl<ApUserRealnameMapper,ApUserRealname> implements ApUserRealnameService {

    */
/**
     * 认证审核列表
     * @param dto
     * @return
     *//*

    @Override
    public ResponseResult loadUserList(AuthDto dto) {
        //判断
        if(dto==null){
            return (PageResponseResult) ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //检查参数
        dto.checkParam();

        LambdaQueryWrapper<ApUserRealname> querywrapper= Wrappers.lambdaQuery();
        //状态判断
        if(dto.getStatus()!=null){
            querywrapper.eq(ApUserRealname::getStatus,dto.getStatus());
        }

        //分页
        Page<ApUserRealname> page1 = new Page<>(dto.getPage(), dto.getSize());

        IPage<ApUserRealname> resultPage = page(page1, querywrapper);
        //封装数据
        ResponseResult responseResult=new PageResponseResult(dto.getPage(),dto.getSize(),(int)resultPage.getTotal());
        responseResult.setData(resultPage.getRecords());

        return responseResult;
    }
    */
/*
    状态审核，status=9表示审核通过，status=2表示审核失败
     *//*

    @Override
    @Transactional
    @GlobalTransactional
    public ResponseResult updateStatusById(AuthDto dto, Short status) {
        //1.检查参数
        if (dto == null || dto.getId()==null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //2判断当前status参数值
        if(!checkStatus(status)){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //3.修改状态
        ApUserRealname apUserRealname=new ApUserRealname();
        apUserRealname.setId(dto.getId());
        apUserRealname.setStatus(status);//有可能等于9,和2
        boolean flag = updateById(apUserRealname);

        if(flag){//修改数据库表成功
            //认证通过，
            if(status.equals(UserConstans.PASS_AUTH)){
                //则添加自媒体和作者
                ResponseResult responseResult= createWmUserAndAuthor(dto);

                int i=1/0;
                return responseResult;
            }
        }else{
            return ResponseResult.errorResult(AppHttpCodeEnum.ERROR);
        }


        return null;
    }

    @Autowired
    private ArticleFeign articleFeign;

    @Autowired
    private WemediaFeign wemediaFeign;

    @Autowired
    private ApUserMapper apUserMapper;

    //则添加自媒体和作者
    private ResponseResult createWmUserAndAuthor(AuthDto dto) {
        //根据认证id去查询
        ApUserRealname userRealname = getById(dto.getId());
        //根据用户id去查询ap_user表
        ApUser apUser = apUserMapper.selectById(userRealname.getUserId());
        if (apUser == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        //通过feign接口调用自媒体保存账户
        WmUser wmUser = wemediaFeign.findByName(apUser.getName());
        if (wmUser == null || wmUser.getId()==null) {
            //创建wmUser
            wmUser=new WmUser();
            //设置ApUserId
            wmUser.setApUserId(apUser.getId());
            wmUser.setSalt(apUser.getSalt());
            wmUser.setName(apUser.getName());
            wmUser.setPassword(apUser.getPassword());
            wmUser.setStatus(9);
            wmUser.setPhone(apUser.getPhone());
            wemediaFeign.insertWmUser(wmUser);
        }
        //通过feign接口调用保存作者的接口
        ApAuthor apAuthor = articleFeign.findByUserId(apUser.getId());
        if(apAuthor==null || apAuthor.getId()==null){
            //创建ap_author
            apAuthor = new ApAuthor();
            apAuthor.setName(wmUser.getName());
            apAuthor.setType(UserConstans.AUTH_TYPE_SELF);
            apAuthor.setUserId(apUser.getId());
            articleFeign.save(apAuthor);
        }
        //更改用户类型
        apUser.setFlag(1);
        apUserMapper.updateById(apUser);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    //自定义的判断状态的方法
    private boolean checkStatus(Short status){
        if (status == null
                || ( !status.equals(UserConstans.FAIL_AUTH)
                && !status.equals(UserConstans.PASS_AUTH))) {
            return false;
        }
        return true;
    }
}
*/
